package cn.lf.controller;


import cn.lf.dto.sys.dict.*;
import cn.lf.service.ISysDictDataService;
import cn.lf.utils.ResponseModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author guoyy
 * @since 2024-04-03
 */
@RestController
@RequestMapping("/sys-dict-data")
@Api(tags = "字典数据管理")
public class SysDictDataController {

    @Autowired
    private ISysDictDataService sysDictDataService;

    @GetMapping("/queryDictDataByType")
    @ApiOperation("根据类型id获取字典数据列表")
    public ResponseModel<List<SysDictDataRepDTO>> queryDictDataByType(SysDictDataReqDTO params){

        List<SysDictDataRepDTO> result = sysDictDataService.queryDictDataByType(params);

        return ResponseModel.buildSuccessResult(result);

    }

    @GetMapping("/getSysDictDataById")
    @ApiOperation("根据id获取字典数据")
    public ResponseModel<SysDictDataInfoDTO> getSysDictDataById(@RequestParam String dictDataId){

        SysDictDataInfoDTO result = sysDictDataService.getSysDictDataById(dictDataId);

        return ResponseModel.buildSuccessResult(result);

    }

    @PostMapping("/saveSysDictData")
    @ApiOperation("保存或更新字典数据")
    public ResponseModel saveSysDictData(@RequestBody SysDictDataSaveDTO sysDictDataSaveDTO){

        sysDictDataService.saveSysDictData(sysDictDataSaveDTO);

        return ResponseModel.buildSuccessResult();
    }

    @GetMapping("/delSysDictData")
    @ApiOperation("删除字典数据")
    public ResponseModel delSysDictData(@RequestParam String dictDataId){

        sysDictDataService.delSysDictData(dictDataId);

        return ResponseModel.buildSuccessResult();

    }

    @GetMapping("/getDictDataByType")
    @ApiOperation("根据类型code获取字典数据")
    public ResponseModel<List<DictDataInfoDTO>> getDictDataByType(@RequestParam String typeCode){

        List<DictDataInfoDTO> result = sysDictDataService.getDictDataByType(typeCode);

        return ResponseModel.buildSuccessResult(result);
    }

}
